use std::collections::BTreeMap;

use ruma::{
    api::client::discovery::get_capabilities::{
        self, Capabilities, RoomVersionStability, RoomVersionsCapability,
        ThirdPartyIdChangesCapability,
    },
    RoomVersionId,
};

use crate::{server::server, utils::ruma_wrapper::Ruma, Result};

/// # `GET /_matrix/client/v3/capabilities`
///
/// Get information on the supported feature set and other relevent capabilities
/// of this server.
pub async fn get_capabilities_route(
    _body: Ruma<get_capabilities::v3::Request>,
) -> Result<get_capabilities::v3::Response> {
    let mut available: BTreeMap<RoomVersionId, RoomVersionStability> = BTreeMap::new();
    available.insert(
        server().config.default_room_version.clone(),
        RoomVersionStability::Stable,
    );

    let mut capabilities = Capabilities::default();
    capabilities.room_versions = RoomVersionsCapability {
        default: server().config.default_room_version.clone(),
        available,
    };

    // we do not implement 3PID stuff
    capabilities.thirdparty_id_changes = ThirdPartyIdChangesCapability { enabled: false };

    Ok(get_capabilities::v3::Response { capabilities })
}
